package cn.yunhe.controller;

import cn.yunhe.entity.News;
import cn.yunhe.service.NewsService;
import cn.yunhe.util.DateUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;

@WebServlet("/AddNewsServlet")
public class AddNewsServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


       String title =request.getParameter("title");
       String context =request.getParameter("context");
       String writeTime=DateUtil.date2StringDateTime(new Date());

       //将新闻id字符串转换成整数
     //int newsid =Integer.parseInt(request.getParameter("newsid"));


        News n =new News();
        n.setTitle(title);
        System.out.println(n.getTitle());
        n.setContext(context);
        n.setWriteTime(writeTime);

        NewsService newsService=new NewsService();
        newsService.addNews(n);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }
}
